<%@page import="backend.Course"%>
<%@page import="frontend.HttpStatus"%>
<%@page import="backend.db.ORM"%>
<%@page import="backend.User"%>
<script type="text/javascript" src="admin/viewStudent.js"></script>
<link rel="stylesheet" type="text/css" href="style/usersTable.css" />
<div id="main-viewStudent" style="font-size:150%; text-align:left;">
	<%
		String username = request.getParameter("username");
		if (null == username) { // no argument was passed
			response.sendError(HttpStatus.SC_BAD_REQUEST);
			return;
		}
		User user = ORM.getUser(username);
		
		if (null != user) {
			if (user.isAdmin()) {
	%>
	<h2>You may only view student details, not administrators.</h2>
	<%		} else { %>
	<fieldset>
		<legend style="font-size:70%;">User general details:</legend>
		<table style="width:50%;">
			<tbody>
				<tr>
					<th style="width:50%;">username:</th>
					<td><%=user.username %></td>
				</tr>
				<tr>
					<th>Full name:</th>
					<td><%=user.name %></td>
				</tr>
				<tr>
					<th>Phone:</th>
					<td><%="".equals(user.phone) ? "Unspecified" : user.phone %></td>
				</tr>
				<tr>
					<th>Address:</th>
					<td><%="".equals(user.address) ? "Unspecified" : user.address %></td>
				</tr>
			</tbody>
		</table>
	</fieldset>
	<br/>
	<%
		Iterable<Course> courses = ORM.getMyCoursesShallow(username);
		if (!courses.iterator().hasNext()) {
	%>
	User isn't registered to any courses.
	<%} else { %>
	<fieldset>
		<legend style="font-size:70%;">User is registered to:</legend>
		<table style="width:100%;">
			<thead>
				<tr>
					<th style="width:25%;">Course name</th>
					<th style="width:10%;">Course id</th>
					<th style="width:5%">Credit points</th>
					<th style="width:5%;">Group number</th>	
					<th style="width:10%;">Moed A</th>
					<th style="width:10%;">Moed B</th>
					<th style="width:10%;">Capacity</th>
					<th style="width:25%;">Lecturer in charge</th>						
				</tr>
			</thead>
			<tbody>
				<%
					for (Course course : courses) {
				%>
				<tr>		
					<td><%=course.courseName %></td>
					<td><%=course.courseId %></td>
					<td><%=course.creditPoints %></td>
					<td><%=course.groupNum %></td>
					<td><%=course.moedA %></td>
					<td><%=course.moedB %></td>		
					<td><%=course.capacity %></td>					
					<td><%=course.lecturerInCharge %></td>
				</tr>
				<%} %>
			</tbody>
		</table>
	</fieldset>
	<%} %>
	<br/>
	<form id="removeStudentForm" method="post" action="#">
		<div>
			<input type="hidden" name="username" value="<%=username %>" />
			<input type="submit" value="Remove" />
			<div id="areYouSure" style="display: none;">
				Are you sure you wish to remove this student, and all data associated with him?<br />
				This request cannot be undone.<br />
				Click the remove button again to confirm.
			</div>
		</div>
	</form>
	<script type="text/javascript">
		setCheckAndPostFormToServletWithCompleteFunc('removeStudentForm', 'admin/removeStudent', areYouSure, function() {$('#allUsersLink').click();});
	</script>
	<%		}
		} else { // user is null (wasn't found)
	%>
	<h2>The requested user does not exist in the system.</h2>
	<%} %>
</div>
